package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.example.Mapper.SalesmanMapper;
import org.example.common.response.ResponseData;
import org.example.entity.Salesman;
import org.example.entity.param.SalesmanParam;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/salesman")
@CrossOrigin
public class SalesmanController {
    @Resource
    SalesmanMapper salesmanMapper;
    @GetMapping("/query")
    public ResponseData query(SalesmanParam salesmanParam){
        LambdaQueryWrapper<Salesman> qw=new LambdaQueryWrapper<>();
            qw.ge(salesmanParam.getLowSal()!=null&&salesmanParam.getHighSal()==null,Salesman::getSal,salesmanParam.getLowSal());
            qw.le(salesmanParam.getHighSal()!=null&&salesmanParam.getLowSal()==null,Salesman::getSal,salesmanParam.getHighSal());
            qw.like(StringUtils.isNotEmpty(salesmanParam.getSaleName()),Salesman::getSaleName,salesmanParam.getSaleName());
            qw.eq(StringUtils.isNotEmpty(salesmanParam.getSex()),Salesman::getSex,salesmanParam.getSex());
            qw.between(salesmanParam.getHighSal()!=null&&salesmanParam.getLowSal()!=null,Salesman::getSal,salesmanParam.getLowSal(),salesmanParam.getHighSal());
            qw.select(Salesman::getId,Salesman::getSaleName,Salesman::getPassword,Salesman::getSex,Salesman::getContact,Salesman::getSal,Salesman::getState);
            salesmanMapper.selectPage(salesmanParam,qw);
            return ResponseData.success(salesmanParam);
    }
}
